<?php

namespace App\Models;

use App\Traits\UseMeter;
use App\Traits\UseOwner;
use Illuminate\Database\Eloquent\Model;

// 建筑
class Building extends Model implements Estate
{
    use UseOwner, UseMeter;

    protected $fillable = [
        'no',
        'name',
        'floor',
        'description',
        'image',
        'public_utilities',
        'room_by_floor',
        'room_prefix',
        'public_utilities',
        'is_rent',
        'is_elevator'
    ];

    const PUBLIC_UTILITIES_CAR_PARK = 'car_park';
    const PUBLIC_UTILITIES_GYM = 'gym';
    const PUBLIC_UTILITIES_SWIMMING_POOL = 'swimming_pool';
    const PUBLIC_UTILITIES_EXPRESS_DELIVERY = 'express_delivery';
    const PUBLIC_UTILITIES_LAUNDRY_ROOM = 'laundry_room';

    public static $publicUtilitiesMap = [
        self::PUBLIC_UTILITIES_CAR_PARK => '停车位',
        self::PUBLIC_UTILITIES_EXPRESS_DELIVERY => '收快递',
        self::PUBLIC_UTILITIES_SWIMMING_POOL => '游泳池',
        self::PUBLIC_UTILITIES_GYM => '健身房',
        self::PUBLIC_UTILITIES_LAUNDRY_ROOM => '洗衣间',
    ];

    protected $casts = [
        'is_rent' => 'boolean',
        'is_elevator' => 'boolean',
        'public_utilities' => 'array'
    ];

    public function house()
    {
        return $this->belongsTo(House::class);
    }

    public function rooms()
    {
        return $this->hasMany(Room::class);
    }
}
